


/**
 * 画点
 */
import Draw from "./Draw";
import Point from '../../entity/type/Point'

const DEF_STYLE = {
  pixelSize: 10,
  outlineColor: Cesium.Color.PURPLE,
  outlineWidth: 5,
  outlineColor : Cesium.Color.YELLOW,
  clampToGround: true
}

export default class DrawPoint extends Draw{

  constructor(style){
    super()
    this._position = Cesium.Cartesian3.ZERO
    this._style = {
      ...DEF_STYLE,
      ...style
    }
    this._message = '右键点击结束'
  }

  _mountEntity() {
    
    this._delegate = new Cesium.Entity({
      position: new Cesium.CallbackProperty(() => {
        return this._position
      }, false),
      point: {
        ...this._style
      }
    })
    this._layer.add(this._delegate)
  }

  _onClick(e) {}

  /**
   * 鼠标跟随移动
   * @param {*} e 当前屏幕位置
   */
  _onMouseMove(e) {
    e = this.getMouseInfo(e.endPosition)
    this._tooltip.showAt(e.windowPosition, this._message)
    this._position = this._clampToGround ? e.surfacePosition : e.position
  }

  /**
   * 右键结束
   * @param {*} e 
   */
  _onRightClick(e){
    e = this.getMouseInfo(e.position)
    this._position = this._clampToGround ? e.surfacePosition : e.position
    this.unbindEvent()
    let point = new Point( this._position)
    point.setStyle(this._style)
    this._plotEvent.raiseEvent(point)
  }
  
}